<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

Integer currPage = Integer.parseInt(request.getParameter("currPage"));
Integer totalPage = Integer.parseInt(request.getParameter("totalPage"));
String action = request.getParameter("action");
%>
<script type="text/javascript">
$(document).ready(function(){
	var action = $(".action").val() + "currPage=";
	var currPage = parseInt($(".currPage").text());
	var totalPage = parseInt($(".totalPage").text());
	
	var jumpObj  = $(".jump");
	var firstObj = $(".first");
	var lastObj  = $(".last");
	var nextObj  = $(".next");
	var previewObj = $(".preview");
	
	//unclick check
	if(currPage == 1 && totalPage == 1){
		hiddenByObjs(new Array(firstObj,previewObj,nextObj,lastObj,jumpObj));
	}else if(currPage == 1){
		hiddenByObjs(new Array(firstObj,previewObj));
	}else if(currPage == totalPage){
		hiddenByObjs(new Array(nextObj,lastObj));
	}
	
	//click events
	firstObj.click(function(){
		alert(action + 1);
	});
	previewObj.click(function(){
		alert(action + (currPage - 1));
	});
	nextObj.click(function(){
		alert(action + (currPage + 1));
	});
	lastObj.click(function(){
		alert(action + totalPage);
	});
	jumpObj.click(function(){
		var jumpNum = checkJumpNum(currPage,totalPage);
		if(jumpNum != null){
			alert(action + jumpNum);
			//jump option
			
		}else{
			//alert("请输入数字！");
			$(".warningMsg").text("请输入正确的数字!");
			$(".jumpNum").val(null);
			$("#myModal").modal("show");
		}
	});
	
});

//set disabled btn by objs
function hiddenByObjs(objs){
	for(var i=0;i<objs.length;i++){
		objs[i].addClass("disabled");
	}
}
//checkJumpNum
function checkJumpNum(currPage,totalPage){
	var exp = new RegExp("^(0|[0-9][1-9]?)$");
	var inputNum = $(".jumpNum").val();
	if(!exp.test(inputNum)){
		return null;
	}else if(inputNum > totalPage){
		return totalPage;
	}else{
		return inputNum;
	}
}

</script>
<div id="rollPage">
	<div id="rollPage_left">
    	<b>
    		<span class="currPage"><%=currPage %></span>&nbsp;/&nbsp;
    		<span class="totalPage"><%=totalPage %></span>&nbsp;   页
    		<input type="hidden" class="action" value="<%=action %>">
    	</b>
	</div>	
	<div id="rollPage_right">
 		<ul class="pager">
		  <li>
		    <a href="javascript:;" class="btn first">首 页</a>
		  </li>
		  <li>
		    <a href="javascript:;" class="btn preview">上一页</a>
		  </li>
		  <li>
		    <a href="javascript:;" class="btn next">下一页</a>
		  </li>
		  <li>
		    <a href="javascript:;" class="btn last">末 页</a>
		  </li>&nbsp;&nbsp;
		  <span><b>跳到</b></span>
		  <li>
		    <input style="width:50px;" type="text" class="form-control jumpNum" />
		  </li>
		  <span><b>页</b></span>
		  <li>
		    <a href="javascript:;" class="btn jump">Go</a>
		  </li>
		</ul>
		</div>
</div>

<!-- 弹出警告框  -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:250px;padding-top:18%;">
		<div class="modal-content">
			<div class="modal-header" align="center">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h5 class="modal-title" id="myModalLabel">
					<span class="text-danger"><span class="glyphicon glyphicon-warning-sign"></span> 警告</span>
				</h5>
			</div>
			<div class="modal-body" align="center">
				<b><span class="warningMsg text-danger"></span></b>
			</div>
		</div>
	</div>
</div>
